home *** CD-ROM | disk | FTP | other *** search
- /* Update.c: Update applet for ProjectDrag.
- *
- * A set of applets for drag and drop source control by Tim Maroney.
- * See develop, issue 23 for details.
- *
- * Built on DropShell by Leonard Rosenthol, Stephan Somogyi, and Marshall Clow,
- * and using the MoreFiles utilities by Jim Luther.
- *
- * This software is free, but don't modify and redistribute it without
- * changing the status window to indicate your name and your changes!
- */
-
-
- #include <Errors.h>
-
- #include "DSUserProcs.h"
- #include "SourceServer.h"
- #include "PDDialogs.h"
- #include "MoreFilesExtras.h"
- #include "TasksAndErrors.h"
- #include "FileCancel.h"
-
-
- void UpdateFile(FSSpec *file, Boolean doingFolder);
- OSErr UpdateFolder(short vRefNum, long folderID,
- void (*doFile)(FSSpec *file, Boolean doingFolder));
-
-
- /* This routine is called for each file passed in the ODOC event. */
-
- pascal void OpenDoc ( FSSpecPtr myFSSPtr, Boolean opening, Handle userDataHandle )
- {
- #pragma unused ( opening )
- #pragma unused ( userDataHandle )
-
- ProcessFileOrFolder(myFSSPtr, UpdateFile, UpdateFolder);
- }
-
-
- void UpdateFile(FSSpec *file, Boolean doingFolder)
- {
- #pragma unused ( doingFolder )
-
- Str63 userName;
- Str15 nickname;
- OSErr err;
- CKIDHandle theCKID;
- AEDesc command;
- Str255 projectName;
-
- TaskStart(2001, 1, file->name, NULL, NULL, NULL);
-
- /* find the user name and initials */
- err = GetUserSettings(userName, nickname, false);
- if (err != noErr)
- {
- gDone = true;
- return;
- }
-
- /* get the CKID */
- err = ExtractCKID(file, &theCKID);
- if (err != noErr)
- {
- RaiseErrorString(kProjectDragStrings, kCantGetCKID, file->name,
- NULL, NULL, NULL);
- return;
- }
-
- /* is the file already checked out or MRO? */
- if ((*theCKID)->modifyReadOnly || (*theCKID)->writeable)
- {
- /* confirm the discard */
- if (!ResTextYesNo(kProjectDragStrings, kConfirmDiscardChanges, file->name, NULL, NULL, NULL))
- {
- DisposeHandle((Handle)theCKID);
- RaiseErrorNumber(userCanceledErr);
- return;
- }
-
- err = FileCancel(file, theCKID);
- DisposeHandle((Handle)theCKID);
- }
- else
- {
- /* not checked out for modify -- create a CheckOut command for SourceServer
- * CheckOut -d <dir> -project <project> <file>
- */
-
- /* mount the project */
- err = MountProjectFromCKID(theCKID, projectName);
- DisposeHandle((Handle)theCKID);
- if (err != noErr) return;
-
- err = CreateCommand(&command, "CheckOut");
- if (err == noErr)
- err = AddDirArg(&command, file->vRefNum, file->parID);
- if (err == noErr)
- err = AddProjectArg(&command, projectName);
- if (err == noErr)
- err = AddPStringArg(&command, file->name);
- if (err != noErr)
- {
- AEDisposeDesc(&command);
- RaiseErrorNumber(err);
- return;
- }
-
- /* send the command to SourceServer */
- err = SendCommand(&command);
- }
-
- if (err == noErr) TaskDone();
- }
-
-
- OSErr UpdateFolder(short vRefNum, long folderID,
- void (*doFile)(FSSpec *file, Boolean doingFolder))
- {
- #pragma unused ( doFile )
-
- Str63 userName;
- Str15 nickname;
- OSErr err;
- AEDesc command;
- Str255 projectName;
-
- /* put the folder name in the status window */
- {
- Str31 folderName;
- err = GetDirName(vRefNum, folderID, folderName);
- if (err != noErr) return err;
- TaskStart(2001, 1, folderName, NULL, NULL, NULL);
- }
-
- /* find the user name and initials */
- err = GetUserSettings(userName, nickname, false);
- if (err != noErr)
- {
- gDone = true;
- return err;
- }
-
- /* mount the project */
- err = MountProjectFromFolder(vRefNum, folderID, projectName);
- if (err != noErr) return err;
-
- /* create a CheckOutDir -r command for SourceServer
- * CheckOut -r -project <project> <dir>
- */
- err = CreateCommand(&command, "CheckOutDir");
- if (err == noErr)
- err = AddCStringArg(&command, "-r");
- if (err == noErr)
- err = AddProjectArg(&command, projectName);
- if (err == noErr)
- {
- FSSpec dirSpec;
- dirSpec.vRefNum = vRefNum;
- dirSpec.parID = folderID;
- dirSpec.name[0] = 0;
- err = AddFileNameArg(&command, &dirSpec);
- }
- if (err != noErr)
- {
- AEDisposeDesc(&command);
- return RaiseErrorNumber(err);
- }
-
- /* send the command to SourceServer */
- err = SendCommand(&command);
- if (err != noErr) return err;
-
- /* create a CheckOut -newer -deleteObsolete -r command for SourceServer
- * CheckOut -newer -deleteObsolete -r -project <project>
- */
- err = CreateCommand(&command, "CheckOut");
- if (err == noErr)
- err = AddCStringArg(&command, "-newer");
- if (err == noErr)
- err = AddCStringArg(&command, "-deleteObsolete");
- if (err == noErr)
- err = AddCStringArg(&command, "-r");
- if (err == noErr)
- err = AddProjectArg(&command, projectName);
- if (err != noErr)
- {
- AEDisposeDesc(&command);
- return RaiseErrorNumber(err);
- }
-
- /* send the command to SourceServer */
- err = SendCommand(&command);
- if (err == noErr)
- TaskDone();
- return err;
- }
-
- void DoFileMenu(short itemID)
- {
- if ( itemID == 1 )
- SelectFile(); // call file selection userProc
- else
- SendQuitToSelf(); // send self a 'quit' event
- }
-